package net.bw.realtime.tmall.mapper;

import net.bw.realtime.tmall.bean.SaleProvinceReport;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/*
 * @ Author：liuyawei
 * @ Date：2025-05-28
 */
public interface SaleProvinceStatsMapper {

    // 省份统计
    @Select("SELECT\n" +
            " province,\n" +
            " sum(order_count) AS sale_count,\n" +
            " sum(total_amount) AS sale_amount\n" +
            "FROM jtp_tmall_report.dws_area_daily_report\n" +
            "WHERE toDate(window_start_time) = #{date}\n" +
            "GROUP BY province")
    List<SaleProvinceReport> selectSaleAmount(String date);

    // 平均省份销售额
    @Select("SELECT\n" +
            "    sum(total_amount) / count(distinct province) / 10000 as avg_province_amount\n" +
            "FROM jtp_tmall_report.dws_area_daily_report\n" +
            "WHERE toDate(window_start_time) = #{date}")
    Double selectProvinceAmount(String date);

    // 平均省份订单数量
    @Select("SELECT\n" +
            "    sum(order_count) * 100 / count(distinct province)  as avg_province_amount\n" +
            "FROM jtp_tmall_report.dws_area_daily_report\n" +
            "WHERE toDate(window_start_time) = #{date}")
    Double selectProvinceOrderCnt(String date);

}
